<?php
// no direct access
defined('_JEXEC') or die('Restricted access');
global $mainframe;
$app = & JFactory::getApplication();
$document =& JFactory::getDocument();

$duration =		 $params->get('slider_duration',3000); 
$container =	 $params->get('slider_container','slideshow'); 
$folder =		 $params->get('image_folder','images/html5_slideshow'); 
$width =		 $params->get('width','1260');
$height =		 $params->get('height','500');
$full_path = JURI::base().$folder.'/';

$document->addScript('http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js');
$document->addScript(JURI::base().'modules/mod_html5slideshow/assets/noconflict.js');
$document->addScript(JURI::base().'modules/mod_html5slideshow/assets/script.js');

$configs ='
html5slideshow = {}
html5slideshow.howLong = '.$duration.';
html5slideshow.mainId = "#'.$container.'";
';
$document->addScriptDeclaration($configs);

$css = '
#'.$container.' {background:url("'.JURI::base().'modules/mod_html5slideshow/assets/ajax-loader.gif") no-repeat center center;height:'.$height.'px;position:relative; left:50%; margin-left:-'.(($width/2)+10).'px; width:'.$width.'px; border:10px solid #fff; }
#'.$container.' ul{height:'.$height.'px; left:0px; list-style:none outside none; overflow:hidden; position:absolute; top:0px; width:'.$width.'px; margin:0; padding:0; }
#'.$container.' li{position:absolute; display:none; z-index:10; margin:0; padding:0; }
#'.$container.' li:first-child{display:block; z-index:1000; }
#'.$container.' .slideActive{z-index:1000; }
#'.$container.' canvas{display:none; position:absolute; z-index:100; margin:0; padding:0; }
#'.$container.' .arrows-wrapper {position:absolute;top:50%; margin-top:-40px; width:960px; left:50%; margin-left:-480px; }
#'.$container.' .arrow{height:80px; width:74px; position:absolute; background:url("'.JURI::base().'modules/mod_html5slideshow/assets/arrows.png") no-repeat;  cursor:pointer; z-index:10000; }
#'.$container.' .previous{ background-position:left top;left:0;}
#'.$container.' .previous:hover{ background-position:left bottom;}
#'.$container.' .next{ background-position:right top;right:0;}
#'.$container.' .next:hover{ background-position:right bottom;}
#rt-showcase .rt-block { height:510px;}
';
$document->addStyleDeclaration($css);

?>


<div id="<?php echo $container; ?>">
<ul class="slides">
<?php
$imageExtensions = array('jpg', 'gif', 'png');
$index = 0;
if (is_dir($folder)) {
	if ($dh = opendir($folder)){
		$files = array();
		while (($file = readdir($dh)) !== false) {
			array_push($files, $file);
		}
		sort($files);
		foreach($files as $file){
			if ($file != '.' && $file != '..') {  
			
				$extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));
				if(is_file($folder .'/'. $file) && in_array($extension, $imageExtensions)){
					$fullImagePath = $full_path . $file;
					echo '<li><img id="img'. $index . '" width="'.$width.'" height="'.$height.'" src="'.$fullImagePath.'" alt="" /></li>';
					$index++;
				}
			}
		}

		if($index == 0)
		{
			echo "Path: \"" . $folder . "\" does not contain images.  Check to make sure files with the appropriate extensions exist in the path.\n";
		}
		closedir($dh);
	}
}
else
{
	echo "Path: \"" . $folder . "\" does not exist<br />\n";
}
?>

</ul>
    <div class="arrows-wrapper">
        <span class="arrow previous"></span>
        <span class="arrow next"></span>
    </div>
</div>